package leetcode.editor.cn.q1_300.q100;

import leetcode.editor.cn.util.tree.btree.TreeNode;

/**
 * @author qidi
 * @date 2022-01-06 15:39:36
 */
class Q0111_MinimumDepthOfBinaryTree {

    //leetcode submit region begin(Prohibit modification and deletion)
    class Solution {
        public int minDepth(TreeNode root) {
            if (root == null) return 0;
            return process(root);
        }

        private int process(TreeNode node) {
            if (node == null) return 0;

            int ld = process(node.left);
            int rd = process(node.right);

            return ld == 0 || rd == 0 ? ld + rd + 1 : Math.min(ld, rd) + 1;
        }
    }
    //leetcode submit region end(Prohibit modification and deletion)


    public static void main(String[] args) {
        Solution solution = new Q0111_MinimumDepthOfBinaryTree().new Solution();
    }
}